|
|
|
|
|
|
|
Figure 1.9
A circle and an ellipse with aspect ratio 2. |
|
|
|
|
|
|
|
|
There are a couple of ways you can make ellipses more easily using custom coordinates. The EllipseWithSegments subroutine shown in the following code draws an ellipse using short line segments. It uses the sine and cosine functions, multiplied by the ellipse's half width and height, to draw the ellipse. Because the Line method does honor custom coordinates, the result is an ellipse in the drawing object's coordinate system. |
|
|
|
 |
|
|
|
|
' Draw an ellipse using line segments. Private Sub EllipseWithSegments(ByVal obj As Object, _
ByVal xmin As Single, ByVal ymin As Single, _
ByVal xmax As Single, ByVal ymax As Single)
Const p = 3.14159265
Dim theta As Single
Dim cx As Single
Dim cy As Single
Dim radius_x As Single
Dim radius_y As Single
Dim X As Single
Dim Y As Single
' Find the center. cx = (xmin + xmax) / 2
cy = (ymin + ymax) / 2
' Find the X and Y half-widths. radius_x = (xmax - xmin) / 2
radius_y = (ymax - ymin) / 2
' Draw the ellipse. obj.CurrentX = cx + radius_x
obj.CurrentY = cy
For theta = 0 To 2 * p Step p / 10
X = cx + radius_x * Cos(theta)
Y = cy + radius_y * Sin(theta)
obj.Line -(X, Y)
Next theta
obj.Line -(cx + radius_x, cy)
End Sub |
|
|
|
|
|